<?php
 include 'template/header.html';
require_once 'lib/function.php';

    $action = isset($_GET['action'])?$_GET['action']:'list';
    switch ($action) {
        case 'list':
            $sql = "select * from notice order by n_time desc";
            $rowNum = getRowNum($sql);
            $page = isset($_GET['page'])?$_GET['page']:1;
            $listNum = 10;
            $maxPage = ceil($rowNum/$listNum);
            $res = page($page,$sql, $listNum);
            include 'template/notice_list.html';

            break;
        case 'add':
        $sqlAdmin = "select admin_name,admin_id from adminlogin";
        $adminArr = getAllData($sqlAdmin);
            include 'template/notice_add.html';
            break;
        case 'add_check':
            $title = isset($_POST['title'])?$_POST['title']:'';
            $content = isset($_POST['content'])?$_POST['content']:'';
            $n_admin = $_POST['n_admin']+0;
            $date  = date("Y-m-d H:i:s");
            $sql = "insert into notice values('','$date','$title','$n_admin','$content')";
            $res = dclData($sql);
            if($res){
                echo "<script>alert('发布成功!');location.href='notice.php'</script>";
            }
            break;
        case 'delete':
            $n_id = $_GET['n_id'];
            $sql = "delete from notice where n_id='$n_id'";
            $res = dclData($sql);
            if($res){
                echo "<script>alert('删除成功!');location.href='notice.php'</script>";
            }
            break;
    }
    include 'template/foot.html';